﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Threading;
using HtmlAgilityPack;
using Extractor.LibCode;


namespace Extractor
{
    public partial class Form1 : Form
    {
        private string sPathdata = "";
        private cBLL oCore;
        private string sform;
        private string[] ssform;
        private int iform;
        private bool bwebbusy;
        string[] snote;
        string[] sextension = new string[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp"};
        //string[] sextension = new string[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".rar", ".zip", ".7z", ".txt" };

        #region property tab Match
        DataTable dtMatch;
        List<cMatch> listoMatch;
        #endregion
        #region property tab Define
        private int currpage;
        cDefineBb odfn;
        DefineBabe stDF;


        #endregion



        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            LOAD_TAB4();
            LOAD_TAB5();
            loadTAB_8_SEO();
            sPathdata = Properties.Settings.Default.pathdata;
            snote = File.ReadAllLines(sPathdata + "\\note.txt");
            cSearchHelp osrc = new cSearchHelp("");
            Properties.Settings.Default.sfilter = txtFilter.Text;
            oCore = new cBLL();
        }




        #region TAB 1
        private void btnAddToListMatch_Click(object sender, EventArgs e)
        {
            foreach (string s in txtDest.Lines)
            {
                lstMatch.Items.Add(s);
            }

            tabControl1.SelectTab("tabMatch");
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            //cXML oxml;
            StringBuilder sb = new StringBuilder();
            cHTML.tesHTML("", out sb);
            txtDest.Text = sb.ToString();
            MessageBox.Show("done");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string[] stemp;//=// txtSource.Text.Split(  new string[]{ System.Environment.NewLine}, StringSplitOptions.None);
            StringBuilder sb = new StringBuilder();
            //string sline = txtSource.Text.Replace("><", ">\r\n<");
            string sline = txtSource.Text.Replace("\n", "\r\n");
            sline = sline.Replace("\r\r\n", "\r\n");
            sline = sline.Replace("><", ">\r\n<");
            stemp = sline.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None);
            foreach (string s in stemp)
            {
                if (s.Trim() != string.Empty)
                {
                    sb.AppendLine(s.Trim());
                }
            }
            txtSource.Text = sb.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            txtSource.Text = string.Join(System.Environment.NewLine, snote);
        }

        private void btnClearAll_Click(object sender, EventArgs e)
        {
            cCommon.ClearTB(new TextBox[] { txtSource, txtDest });
        }

        private void txtFilter_Leave(object sender, EventArgs e)
        {
            Properties.Settings.Default.sfilter = txtFilter.Text;
            Properties.Settings.Default.Save();
        }

        private void btnFilter_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string s in txtSource.Lines)
            {
                if (s.Contains(txtFilter.Text))
                {
                    sb.AppendLine(s);

                }
            }
            StreamWriter sw = new System.IO.StreamWriter(sPathdata + "\\output1.txt", false);
            sw.Write(sb.ToString());
            sw.Close();
            txtDest.Text = sb.ToString();
        }

        private void txtSource_KeyDown(object sender, KeyEventArgs e)
        {
            cCommon.selectall(sender, e);

        }

        private void txtDest_KeyDown(object sender, KeyEventArgs e)
        {
            cCommon.selectall(sender, e);

        }

        private void btnGetInnerHTML_Click(object sender, EventArgs e)
        {
            string[] sdesc = txtDest.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            string stemp = "";
            StringBuilder sb = new StringBuilder();
            foreach (string s in sdesc)
            {
                if (s.Trim() != string.Empty)
                {
                    int idx = 0;
                    int x = 0;
                    int y = 0;
                    while (idx != -1)
                    {
                        // x = y = -1;
                        x = s.IndexOf(">", idx);
                        if (x != -1)
                            y = s.IndexOf("<", x);
                        if (x != 1 & y != -1)
                            stemp = s.Substring(x + 1, (y - x) - 1);

                        idx = y;
                        if (x == -1 || y == -1)
                            idx = -1;
                        else
                            if (stemp.Trim() != string.Empty)
                                sb.AppendLine(stemp);
                    }
                }
            }
            fOutput fo = new fOutput();
            fo.soutput = sb.ToString();
            fo.Show();
        }

        private void btnGetProperties_Click(object sender, EventArgs e)
        {
            string[] sline = cCommon.getArraystring(txtDest);
            StringBuilder sb = new StringBuilder();
            foreach (string s in sline)
            {
                string stype = "\"";
                int x = 0;
                if (cbIsInner.Checked)
                {
                    x = s.IndexOf(txtPropertyName.Text + "=");
                    stype = txtEndChar.Text;
                }
                else
                {
                    x = s.IndexOf(txtPropertyName.Text + "=\"");
                    if (x == -1)
                    {
                        x = s.IndexOf(txtPropertyName.Text + "='");
                        stype = "'";

                    }
                }


                if (x != -1)
                {
                    int y = 0;
                    if (cbIsInner.Checked)
                    {
                        y = s.IndexOf(stype, x);
                        if (y != -1)
                        {
                            x = x + txtPropertyName.Text.Length + 1;
                            y = y - x;
                            string ss = s.Substring(x, y);//s.Substring(x,y-1);
                            if (ss.Trim() != string.Empty)
                            {
                                sb.AppendLine(ss);
                            }
                        }

                    }
                    else
                    {
                        y = s.IndexOf(stype, x + txtPropertyName.Text.Length + 2);
                        if (y != -1)
                        {
                            x = x + txtPropertyName.Text.Length + 2;
                            y = y - x;
                            string ss = s.Substring(x, y);//s.Substring(x,y-1);
                            if (ss.Trim() != string.Empty)
                            {
                                sb.AppendLine(ss);
                            }
                        }
                    }


                }
            }
            fOutput fo = new fOutput();
            fo.soutput = sb.ToString();
            fo.Show();


        }

        private void btnGetURL_Click(object sender, EventArgs e)
        {
            WebClient client = new WebClient();
            String htmlCode = client.DownloadString(txtURLSource1.Text);

            if (htmlCode != null)
            {
                txtSource.Text = htmlCode;
            }




        }
        #endregion

        #region TAB 2
        private void btnReplace2_Click(object sender, EventArgs e)
        {
            string[] sline = cCommon.getArraystring(txtSRC2);
            StringBuilder sb = new StringBuilder();
            foreach (string s in sline)
            {
                if (s.Trim() != string.Empty)
                {
                    sb.AppendLine(txtUrlReplace.Text.Replace("*", s));

                }

            }

            txtDST2.Text = sb.ToString();
        }

        #endregion

        #region TAB 3

        private void btnProces3_Click(object sender, EventArgs e)
        {
            webBrowser3.Navigate("http://www.detik.com/");
        }
        private void btnTessCon_Click(object sender, EventArgs e)
        {
            MessageBox.Show(oCore.tesconn().ToString());




        }
        private void btngetCode_Click(object sender, EventArgs e)
        {
            //    string s = webBrowser3.DocumentText;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<html>");
            sb.AppendLine("<body>");
            sb.AppendLine("<h1>yanuar");

            sb.AppendLine("</h1>");

            sb.AppendLine("</body>");

            sb.AppendLine("</html>");
            //            webBrowser3.DocumentText = sb.ToString();

            //            var theButton = webBrowser3.Document.GetElementById("btnK");
            //            theButton.Click+=new HtmlElementEventHandler(theButton_Click);
            //theButton.Click += (sender, args) => { ... };
            //var actions = new List<string>();
            //if (webBrowser3.Document != null)
            //{
            //    actions.AddRange(from HtmlElement form in webBrowser3.Document.Forms select form.GetAttribute("action"));
            //}

            //HtmlElement form = webBrowser3.Document.GetElementById("FormID");
            //if (form != null)
            //    form.InvokeMember("submit");

            //HtmlDocument hd = webBrowser3.Document;

            string s = webBrowser3.DocumentText;
            s = s.Replace("name=\"oauth_signup_client[fullname]\"", "name=\"oauth_signup_client[fullname]\" value=\"yanuar\" ");

            webBrowser3.DocumentText = s;



        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            //  webBrowser3.Navigate("http://twitter.com/session/new");
            //var actions = new List<string>();
            //if (webBrowser3.Document != null)
            //{
            //    actions.AddRange(from HtmlElement form in webBrowser3.Document.Forms select form.GetAttribute("action"));
            //}

            // <div class="signup"><a href="/session/new">Sign in</a></div>
            var elements = webBrowser3.Document.GetElementsByTagName("a");
            foreach (HtmlElement element in elements)
            {
                string s = element.GetAttribute("href");
                if (element.GetAttribute("href") == "http://news.detik.com/?ctn")
                    element.InvokeMember("click");
            }





        }

        //private void newweb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        //{
        //    switch (iStages)
        //    {
        //        case 1:
        //            newweb.Document.GetElementById("card_num").SetAttribute("value", strCardNum);
        //            newweb.Document.GetElementById("ch_but_logon").InvokeMember("click");
        //            iStages = 2;
        //            break;
        //        case 2:
        //            newweb.Document.GetElementById("passwd").SetAttribute("value", psswd);
        //            newweb.Document.GetElementById("ch_but_logon").InvokeMember("click");
        //            iStages = 3;
        //            break;
        //    }

        //}
        private void webBrowser3_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {


        }

        #endregion

        #region TAB 4 MATCH
        private void LOAD_TAB4()
        {
            cCommon.fillCombobox(cbCompetition, "competitiondsc1", "competitionid", "tbcompetition");
            cCommon.fillCombobox(cbSession, "sessiondsc", "sessionid", "tbsession");
            cCommon.fillCombobox(cbRound, "codemiddsc", "codeval", DICTIOARY_TYPE.ROUND_DSC);
            listoMatch = new List<cMatch>();
            dtMatch = new DataTable();
            //dtMatch = cCommon.initTable(new string[] { "MatchID","tanggal", "teamA_ID", "teamA_name", "scoretime", "teamB_ID", "teamB_name" });
            gvMatch.DataSource = dtMatch;
            //cMatch oMatch = new cMatch();
            //oMatch.ExtractMatch(ref dtMatch,"http://www.scoresway.com/b/block.competition_matches?gameweek=9&round_id=17950&season_id=7185&competition_id=8&stamp=1352709900&sport=soccer&localization_id=www");
            //cbStage.SelectedText = oMatch.Intstage.ToString();
            //cbRound.SelectedValue = oMatch.Roundtype;
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            foreach (string suri in lstMatch.Items)
            {
                lbldsc.Text = "Extract Match: URI - " + suri;
                if (suri.Trim() != string.Empty)
                {
                    listoMatch.Add(new cMatch(suri));
                }
                //break;
            }

            if (listoMatch.Count > 0)
                gvMatch.DataSource = listoMatch[0].dtMatch;

            cbStage.SelectedIndex = listoMatch[0].Intstage - 1;
            cbRound.SelectedValue = listoMatch[0].Roundtype;
            cbCompetition.SelectedValue = listoMatch[0].Competitionid;
            cbSession.SelectedValue = listoMatch[0].Sessionid;


        }

        private void btnSaveMatch_Click(object sender, EventArgs e)
        {
            foreach (cMatch om in listoMatch)
            {
                om.Save();
            }
        }

        private void btn4_Click(object sender, EventArgs e)
        {
            fSRC osrc = new fSRC();
            osrc.srchelp_name = "SRCTEAM";
            bool ok;

            if (osrc.ShowDialog() == DialogResult.OK)
            {
                label5.Text = osrc.retval;
                //textBox2.Text = osrc.retdesc;
            }
        }

        private void lstMatch_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int idx = lstMatch.SelectedIndex;
            lbldsc.Text = lstMatch.Items[idx].ToString();
            //return;
            if (idx >= 0)
            {
                gvMatch.DataSource = listoMatch[idx].dtMatch;
                cbStage.SelectedIndex = listoMatch[idx].Intstage - 1;
                cbRound.SelectedValue = listoMatch[idx].Roundtype;
                cbCompetition.SelectedValue = listoMatch[idx].Competitionid;
                cbSession.SelectedValue = listoMatch[idx].Sessionid;

            }

        }

        #endregion

        #region TAB 5 Define
        private void btnModelSearch_Click(object sender, EventArgs e)
        {
            fSRC osrc = new fSRC();
            osrc.srchelp_name = "SRCMODEL";
            bool ok;

            if (osrc.ShowDialog() == DialogResult.OK)
            {
                //label5.Text = osrc.retval;
                txtmodelid.Text = osrc.retval;
                //textBox2.Text = osrc.retdesc;
            }
        }

        private void flowGall_MouseEnter(object sender, EventArgs e)
        {
            flowGall.Focus();
        }

        void Readfolder(string ss)
        {
            //  string spath = "c:\\kb\\";
            string[] dir = new string[] { };
            dir = Directory.GetDirectories(ss);
            string[] flnm = new string[] { };
            flnm = Directory.GetFiles(ss);
            foreach (string fl in flnm)
            {
                //ls.AppendLine(s);
                lstFile.Add(fl);

            }
            foreach (string s in dir)
            {
                if (!s.Contains("D:\\Mentah\\Sng\\SNG\\PIC\\DEFINE"))
                    Readfolder(s);

            }


            //  string spath = "D:\\Gambar\\Beatles\\Beatles.jpg";
            //File.GetCreationTime (spath);




        }
        List<string> lstFile = new List<string>();

        private void btnCatetfile_Click(object sender, EventArgs e)
        {

            string spath = "D:\\Mentah\\Sng\\SNG\\PIC\\";

            //spath = "C:\\KB\\";
            //spath="C:\\Downloads\\IDA_Portable\\08092012\\cache.images.globalsportsmedia.com\\soccer\\teams\\150x150\\";
            string[] dir = new string[] { };
            string[] flnm = new string[] { };


            dir = Directory.GetDirectories(spath);
            StringBuilder sb = new StringBuilder();
            //flnm = Directory.GetFiles(spath);
            Readfolder(spath);
            MessageBox.Show("ready to Upload");
            File_Attribute fa = new File_Attribute();
            int i = 0;
            foreach (string s in lstFile)
            {
                fa = new File_Attribute();
                //sb.AppendLine(s);
                i++;

                if (i <= int.Parse(txtSQLDefine.Text))
                    continue;
                    FileInfo f = new FileInfo(s);
                    fa.filesize = f.Length.ToString();
                    fa.filename = f.Name;
                    fa.extension = f.Extension;

                    fa.dtcreated = f.LastWriteTime.ToString();
                    fa.dtmodified = f.CreationTime.ToString();
                    fa.flpath = f.DirectoryName;
                    var sql = from ext in sextension
                              where ext.Equals(f.Extension)
                              select ext;

                    if (sql.Count() > 0)
                    {
                        try
                        {
                            Image im = new Bitmap(s);
                            fa.flHeight = im.Height.ToString();
                            fa.flWidth = im.Width.ToString();
                            fa.fldimension = string.Join(" x ", fa.flWidth, fa.flHeight);
                        }
                        catch
                        {
                            fa.BROKEN = "Y";
                        }
                     
                    }

                    if (fa.extension != ".db" && fa.extension != ".IDAf") 
                    new cFileManagement().catetfiletodb(fa);
                    //sb.AppendLine(f.Length.ToString());

                  
                
            }
            //  txtdefineoutput.Text = sb.ToString();
            MessageBox.Show("DONE");



        }

        private void btnDelThumb_Click(object sender, EventArgs e)
        {

            #region OLDCODE
            //string spath = "D:\\Mentah\\Sng\\SNG\\PIC\\";
            ////spath = "D:\\Mentah\\Sng\\SNG\\PIC\\assparade\\";
            ////spath = "C:\\KB\\";
            ////spath="C:\\Downloads\\IDA_Portable\\08092012\\cache.images.globalsportsmedia.com\\soccer\\teams\\150x150\\";
            //string[] dir = new string[] { };
            //string[] flnm = new string[] { };


            //dir = Directory.GetDirectories(spath);
            //StringBuilder sb = new StringBuilder();
            ////flnm = Directory.GetFiles(spath);
            //Readfolder(spath);
            ////MessageBox.Show("ready to Upload");
            //File_Attribute fa = new File_Attribute();
            //int i = 0;
            //foreach (string s in lstFile)
            //{
            //    fa = new File_Attribute();
            //    //sb.AppendLine(s);
            //    i++;


            //    FileInfo f = new FileInfo(s);
            //   // fa.filesize = f.Length.ToString();
            //    //fa.filename = f.Name;
            //    fa.extension = f.Extension;
            //    var sql = from ext in sextension
            //              where ext.Equals(f.Extension.ToLower())
            //              select ext;

            //    if (sql.Count() == 0)
            //    {
            //        try
            //        {
            //            f.Delete();
            //        }
            //        catch
            //        {
            //        }
            //    }



            //    //sb.AppendLine(f.Length.ToString());

            //    //  new cFileManagement().catetfiletodb(fa);

            //}
            ////  txtdefineoutput.Text = sb.ToString(); 
            #endregion

            new cFileManagement().deletefile();
            MessageBox.Show("DONE");
        }

        void setStrukDF()
        {
            stDF = new DefineBabe();
            stDF.COUNTRY = cbCountry.Text;
            stDF.CUP = cbCup.Text;
            stDF.ETNIC = cbEtnic.Text;
            stDF.Umur = cbUmur.Text;
            if (txtmodelid.Text.Trim() != string.Empty)
            {
                int i = 0;
                if (int.TryParse(txtmodelid.Text.Trim(), out i))
                {
                    stDF.MODELID = txtmodelid.Text.Trim();
                }
                else
                {
                    stDF.NAME = txtmodelid.Text.Trim();
                }
            }

        }

        void loadingflowpanelmodel(DataTable dt)
        {
            flowLayout.Controls.Clear();

            if (dt.Rows.Count > 0)
                foreach (DataRow dr in dt.Rows)
                {

                    gall g = new gall();
                    g.lblname.Text = dr["name"].ToString();
                    //g.pictBox.BackColor=Color.Yellow;       
                    string spath = Properties.Settings.Default.dfpath + "\\MODEL\\" + odfn.getfolder(int.Parse(dr["modelid"].ToString()), 1000) + "\\" + dr["modelid"].ToString() + ".jpg";
                    g.simgpath = spath;
                     g.pictBox.Load(spath);
                    g.pictBox.Tag = dr["modelid"].ToString();
                    // g.Click += new EventHandler(g_Click);
                    //g.pictBox.Click += new EventHandler(pictBox_Click);
                    g.DoubleClick += new EventHandler(g_DoubleClick);
                    g.pictBox.DoubleClick += new EventHandler(pictBox_DoubleClick);
                    flowLayout.Controls.Add(g);
                }

        }
        void loadingflbkp(DataTable dt)
        {
            flowLayout.Controls.Clear();
            int i = 0;
            if (dt.Rows.Count > 0)
                foreach (DataRow dr in dt.Rows)
                {
                    string spath = dr["spath"].ToString(); //Properties.Settings.Default.dfpath + "\\MODEL\\" + odfn.getfolder(int.Parse(dr["modelid"].ToString()), 1000) + "\\" + dr["modelid"].ToString() + ".jpg";
                    if (!File.Exists(spath))
                        continue;
                    i++;
                    if (i == 1000)
                        break;

                    gall g = new gall();                  
                    
                    g.pictBox.Height = 200;
                    g.pictBox.Width = 200;
                    g.pictBox.SizeMode=PictureBoxSizeMode.StretchImage;
                    g.pictBox.Load(spath);
                    g.simgpath = spath;
                    g.Width = 210;
                    g.Height = 210;
                       
                    flowLayout.Controls.Add(g);
                }
            if (i == 0)
                MessageBox.Show("image Not found");
        }
        private void btnLoadPicbox_Click(object sender, EventArgs e)
        {
            #region OLD CODe
            odfn = new cDefineBb();
            setStrukDF();
            DataTable dt = new DataTable();
            dt = odfn.modelinquiry(stDF, 1);
            loadingflowpanelmodel(dt);
            tbdefine.SelectedIndex = 1; 
            #endregion


           

        }

        void pictBox_DoubleClick(object sender, EventArgs e)
        {
            loadmodelgallery(((PictureBox)sender).Tag.ToString());
            tbdefine.SelectedIndex = 2;
        }

        void g_DoubleClick(object sender, EventArgs e)
        {
            loadmodelgallery(((PictureBox)sender).Tag.ToString());
            tbdefine.SelectedIndex = 2;
        }

        void loadmodelgallery(string modelid)
        {
            flowGall.Controls.Clear();

            if (odfn == null)
                odfn = new cDefineBb();
            ModelGallery mg = new ModelGallery();
            mg.MODELID = modelid;
            DataTable dt = new DataTable();
            dt = odfn.galleryInquiry(mg);

            foreach (DataRow dr in dt.Rows)
            {

                gall g = new gall();
                if (dr["thumbdownloaded"].ToString() == "Y")
                {
                    //   g.pictBox.Load(Properties.Settings.Default.dfpath + "\\GALLERY\\" + odfn.getfolder(int.Parse(dr["GALLERYID"].ToString()), 2000) + "\\" + dr["GALLERYID"].ToString() + ".jpg");

                }
                g.lblname.Text = dr["galtitle"].ToString().Trim();
                flowGall.Controls.Add(g);
            }





        }
        void pictBox_Click(object sender, EventArgs e)
        {

            loadmodelgallery(((PictureBox)sender).Tag.ToString());
            tbdefine.SelectedIndex = 1;

        }

        void g_Click(object sender, EventArgs e)
        {


        }


        public System.Drawing.Image DownloadImageFromUrl(string imageUrl)
        {
            System.Drawing.Image image = null;

            try
            {
                System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl);
                webRequest.AllowWriteStreamBuffering = true;
                webRequest.Timeout = 30000;

                System.Net.WebResponse webResponse = webRequest.GetResponse();

                System.IO.Stream stream = webResponse.GetResponseStream();

                image = System.Drawing.Image.FromStream(stream);

                webResponse.Close();
            }
            catch (Exception ex)
            {
                return null;
            }

            return image;
        }

        //just note
        void LoadTAB5()
        {
            #region note
            //            public System.Drawing.Image DownloadImageFromUrl(string imageUrl)
            //{
            //    System.Drawing.Image image = null;

            //    try
            //    {
            //        System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl);
            //        webRequest.AllowWriteStreamBuffering = true;
            //        webRequest.Timeout = 30000;

            //        System.Net.WebResponse webResponse = webRequest.GetResponse();

            //        System.IO.Stream stream = webResponse.GetResponseStream();

            //        image = System.Drawing.Image.FromStream(stream);

            //        webResponse.Close();
            //    }
            //    catch (Exception ex)
            //    {
            //        return null;
            //    }

            //    return image;
            //} 



            //protected void btnSave_Click(object sender, EventArgs e)
            //{
            //    System.Drawing.Image image = DownloadImageFromUrl(txtUrl.Text.Trim());

            //    string rootPath = @"C:\DownloadedImageFromUrl";
            //    string fileName = System.IO.Path.Combine(rootPath, "test.gif");
            //    image.Save(fileName);
            //}



            //            Image tmpimg = null;
            //HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
            //HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
            //Stream stream = httpWebReponse.GetResponseStream();
            //return Image.FromStream(stream);



            //            using (WebClient Client = new WebClient ())
            //{
            //    Client.DownloadFile("http://www.mywebsite.com/img.aspx?imgid=12345", "12345.jpg");
            //}
            #endregion


        }

        private void LOAD_TAB5()
        {

            cDefineBb odfn = new cDefineBb();
            //odfn.getAllModel();
            //odfn.getModelPage("http://www.definebabe.com/models/s/", false);
            //odfn.getModelPageAll();
            //  odfn.getAllModelDetail();

            cCommon.fillCombobox(cbCountry, "country", "country", "vwmodelcountry");
            cCommon.fillCombobox(cbEtnic, "etnic", "etnic", "vwmodeletnic");
            cCommon.fillCombobox(cbUmur, "umur", "umur", "vwmodelumur");
            cCommon.fillCombobox(cbCup, "cup", "cup", "vwmodelcup");
            cbTotThread.SelectedIndex = 3;


        }

        void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {

        }

        void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            MessageBox.Show("completed");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //string spath = "c:\\";

            //WebClient Client = new WebClient();
            //Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted);
            //Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Client_DownloadProgressChanged);
            //Client.DownloadFileAsync(new Uri("http://bl.definebabe.com/9/91/26919/thumb2/06.jpg"), @"C:\temp\_005.jpg");
            //Client.BaseAddress = "http://bl.definebabe.com/9/91/26919/thumb2/06.jpg";

            //cDefineBb odfn = new cDefineBb();
            //odfn.getALLModelGalleries();
            //MessageBox.Show("done");

            //odfn = new cDefineBb();
            //string shtml = odfn.getHTMLModelGallery("003750", false);
            //    wbDefine.DocumentText = shtml;


            odfn = new cDefineBb();


            odfn.downloadmodelgallerydet("", cbTotThread.SelectedIndex + 1);


            // odfn.downloadModel(5);
            //MessageBox.Show("done");

            // cDownlod odn = new cDownlod();


        }


        private void btnDFNLoad_Click(object sender, EventArgs e)
        {
            odfn = new cDefineBb();
            stDF = new DefineBabe();
            stDF.COUNTRY = cbCountry.Text;
            stDF.CUP = cbCup.Text;
            stDF.ETNIC = cbEtnic.Text;
            stDF.Umur = cbUmur.Text;
            if (txtmodelid.Text.Trim() != string.Empty)
            {
                int i = 0;
                if (int.TryParse(txtmodelid.Text.Trim(), out i))
                {
                    stDF.MODELID = txtmodelid.Text.Trim();
                }
                else
                {
                    stDF.NAME = txtmodelid.Text.Trim();
                }
            }
            currpage = 1;
            string shtml = odfn.getHTMLImageModel(stDF, 1);

            // wbDefine.DocumentText = shtml;



        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (currpage > 1)
                currpage--;
            string shtml = odfn.getHTMLImageModel(stDF, currpage);
            wbDefine.DocumentText = shtml;


        }
        void deleteimage(bool bselect)
        {
            foreach (Control ct in flowLayout.Controls)
            {
                gall g = (gall)ct;
                if (g.isselect == bselect)
                {
                    if(File.Exists(g.simgpath))
                    {
                        File.Delete(g.simgpath);
                    }
                }
            }
            MessageBox.Show("done");
        }
        private void btnLoadflbkp_Click(object sender, EventArgs e)
        {
            odfn = new cDefineBb();
            DataTable dt = new DataTable();
            dt = odfn.getimgbkp(txtSQLDefine.Text);
            if (dt.Rows.Count > 0)
            {
                loadingflbkp(dt);
                tbdefine.SelectedIndex = 1;
            }
            else
            {
                MessageBox.Show("image not found");
            }
        }
        private void btnSelect_Click(object sender, EventArgs e)
        {
            deleteimage(true);
        }

        private void btnUnselect_Click(object sender, EventArgs e)
        {
            deleteimage(false);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            currpage++;
            //string shtml = odfn.getHTMLImageModel(stDF, currpage);
            //if (shtml != string.Empty)
            //{
            //    wbDefine.DocumentText = shtml;
            //}
            //else
            //{
            //    wbDefine.DocumentText = "<html><head><body>Records Not Found</body></head></html>";
            //}


            odfn = new cDefineBb();

            setStrukDF();
            DataTable dt = new DataTable();
            dt = odfn.modelinquiry(stDF, currpage);
            loadingflowpanelmodel(dt);


        }

        private void flowLayout_MouseEnter(object sender, EventArgs e)
        {
            flowLayout.Focus();
        }



        #endregion

        #region TAB 6 SUBMIT

        private void btnLoad6_Click(object sender, EventArgs e)
        {
            WebClient client = new WebClient();
            string myuri = "http://iklangratispasang.org/iklan/pasang";
            string pagehtml = client.DownloadString(myuri);
            txtSubmitSource.Text = pagehtml;
            



        }


        #endregion

        #region TAB 8 SEO
        void loadTAB_8_SEO()
        {
            ssform = File.ReadAllLines(Properties.Settings.Default.pathdata + "\\note.txt");
            iform =150;

        }
        private void button6_Click(object sender, EventArgs e)
        {
            //sform = "http://www.kutaukumau.com/submit/?url=http://urbancoture.blogspot.com/2012/12/kaos-007-james-bond.html";
           // sform = "http://www.kutaukumau.com";
           // WebClient client = new WebClient();
            //String htmlCode = client.DownloadString(sform);

            //iform = 0;
            //browserSEO.DocumentText=htmlCode;
          //  browserSEO.Navigate(sform);



        }

        private void loadwebseo()
        {
            browserSEO.Navigate(sform);
            bwebbusy = true;
        }
        private void browserSEO_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
           txtURLSEO.Text = ssform[iform]+"       "+iform.ToString()+ "     "+ browserSEO.Url;

          //  bwebbusy = false;
        //    browserSEO.Document.GetElementById("tags").SetAttribute("value", "tagskjhkjhkjhkjhkjh");
           
        }

        private void button7_Click(object sender, EventArgs e)
        {
            iform++;
            browserSEO.Navigate(ssform[iform]);

            txtURLSEO.Text = ssform[iform];


            return;
            //string scode = browserSEO.DocumentText;
            //scode.Replace("<input type=\"text\" id=\"tags\" class=\"wickEnabled\" name=\"tags\" value=\"\" size=\"54\" maxlength=\"40\" /><br /><br />", "<input type=\"text\" id=\"tags\" class=\"wickEnabled\" name=\"tags\" value=\"tags,tagss,ta\" size=\"54\" maxlength=\"40\" /><br /><br />");
            browserSEO.Document.GetElementById("tags").SetAttribute("value", "tagskjhkjhkjhkjhkjh");
            browserSEO.Document.GetElementById("title").SetAttribute("value", "title title");
            browserSEO.Document.GetElementById("bodytext").InnerText="tes body text";
            
            //bodytext
                //Document.All.GetElementsByName("username")[0].SetAttribute("Value", "SomeUser");
            
        }

        private void button8_Click(object sender, EventArgs e)
        {
            iform--;
            browserSEO.Navigate(ssform[iform]);

            //iform++;
            return;

        }

        /// <summary>
        /// register
        /// </summary>  
        private void button10_Click(object sender, EventArgs e)
        {
            browserSEO.Document.GetElementById("reg_username").SetAttribute("value",txtUIDSEO.Text );
            browserSEO.Document.GetElementById("reg_email").SetAttribute("value", txtEmailSEO.Text);
            browserSEO.Document.GetElementById("reg_password").SetAttribute("value", txtpasswordseo.Text);
            browserSEO.Document.GetElementById("reg_verify").SetAttribute("value", txtpasswordseo.Text);
   

        }

        private void button9_Click(object sender, EventArgs e)
        {
            browserSEO.Navigate(ssform[iform]);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            StreamWriter sw = new StreamWriter(Properties.Settings.Default.pathdata + "\\pliggout.txt", true);
            sw.WriteLine(ssform[iform]);
            sw.Close();
        }

        #endregion

     

      
       

       
       
     
    


























    }
}
